package com.example.jiaowuchu.jiaowuSys.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.example.jiaowuchu.jiaowuSys.dao.UserDao;
import com.example.jiaowuchu.jiaowuSys.pojo.yhpojo.User;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
        private static DataSource ds=null;
        static {
            try {
                Properties p=new Properties();
                p.load(PropertiesUtil.class.getClassLoader().getResourceAsStream("dbpool.properties"));
                ds= DruidDataSourceFactory.createDataSource(p);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    /**
     * 获取数据库连接对象
     * @return
     */
    public static Connection getConnection(){
        Connection connection = null;
        try {
            connection = ds.getConnection();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return connection;
    }

    public static void main(String[] args) {
        System.out.println(DBUtil.getConnection());
        UserDao userDao=new UserDao();


    }
}
